//////////////////////////////////////////////////////////////////////////
#pragma once
#pragma managed
//////////////////////////////////////////////////////////////////////////
using namespace System;
using namespace System::Runtime::InteropServices;
//////////////////////////////////////////////////////////////////////////
NAMESPACE_BEGIN
//////////////////////////////////////////////////////////////////////////
/// <summary>
/// CalEigenCallback
/// </summary>
[UnmanagedFunctionPointerAttribute(CallingConvention::Cdecl)]
public delegate void CalEigenCallback(int index, IntPtr buffer, IntPtr user_data);

/// <summary>
/// CalEigenInput
/// </summary>
/// <param name="pos"></param>
[StructLayoutAttribute(LayoutKind::Explicit)]
public value struct EigenInput
{
	[FieldOffsetAttribute(0)]
	IntPtr callback;
	[FieldOffsetAttribute(0)]
	IntPtr data;
};
/// <summary>
/// 1D/2D HMM
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct ImgObsInfo
{
	int obs_x;
	int obs_y;
	int obs_size;
	IntPtr obs;
	/// <summary>
	/// arr of pairs superstate/state to which observation belong
	/// </summary>
	IntPtr state;
	/// <summary>
	/// number of mixture to which observation belon
	/// </summary>
	IntPtr mix;
};

/// <summary>
/// 1D/2D HMM
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct ObsInfo1D
{
	int obs_x;
	int obs_y;
	int obs_size;
	IntPtr obs;
	/// <summary>
	/// arr of pairs superstate/state to which observation belong
	/// </summary>
	IntPtr state;
	/// <summary>
	/// number of mixture to which observation belon
	/// </summary>
	IntPtr mix;
};

/// <summary>
/// EHMMState
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct EHMMState
{
	/// <summary>
	/// number of mixtures in this state
	/// </summary>
	int num_mix;
	/// <summary>
	/// mean vectors corresponding to each mixture
	/// </summary>
	IntPtr mu;
	/// <summary>
	/// square root of inversed variances corresp. to each mixture
	/// </summary>
	IntPtr inv_var;
	/// <summary>
	/// sum of 0.5 (LN2PI + ln(variance[i]) ) for i=1,n
	/// </summary>
	IntPtr log_var_val;
	/// <summary>
	/// array of mixture weights. Summ of all weights in state is 1
	/// </summary>
	IntPtr weight;
};

/// <summary>
/// EHMM
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct EHMM
{
	/// <summary>
	/// 0 - lowest(i.e its states are real states), .....
	/// </summary>
	int level;
	/// <summary>
	/// number of HMM states
	/// </summary>
	int num_states;
	/// <summary>
	/// transition probab. matrices for states
	/// </summary>
	IntPtr transP;
	/// <summary>
	/// if level == 0 - array of brob matrices corresponding to hmm
	/// if level == 1 - martix of matrices
	/// </summary>
	IntPtr obsProb;
	/// <summary>
	/// if level == 0 points to real states array,
	/// if not - points to embedded hmms
	/// </summary>
	IntPtr u;
};

/// <summary>
/// GraphWeightedVtxFields
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct GraphWeightedVtxFields
{
	GraphVertexFields vertex_fields;
	float weight;
};

// <summary>
/// GraphWeightedVtx
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct GraphWeightedVtx
{
	GraphWeightedVtxFields fields;
};

/// <summary>
/// GraphWeightedEdgeFields
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct GraphWeightedEdgeFields
{
	GraphEdgeFields edge_fields;
};

/// <summary>
/// GraphWeightedEdge
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct GraphWeightedEdge
{
	GraphWeightedEdgeFields fields;
};

/// <summary>
/// Stereo correspondence
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct CliqueFinder
{
	IntPtr graph;
	IntPtr adj_matr;
	int N;
	/// <summary>
	/// graph size stacks, counters etc
	/// </summary>
	int k;
	/// <summary>
	/// stack size
	/// </summary>
	IntPtr current_comp;
	IntPtr All;
	IntPtr ne;
	IntPtr ce;
	IntPtr fixp;
	/// <summary>
	/// node with minimal disconnections
	/// </summary>
	IntPtr nod;
	IntPtr s;
	/// <summary>
	/// for selected candidate
	/// </summary>
	int status;
	int best_score;
	int weighted;
	int weighted_edges;
	float best_weight;
	IntPtr edge_weights;
	IntPtr vertex_weights;
	IntPtr cur_weight;
	IntPtr cand_weight;
};

/// <summary>
/// Epiline functions
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct StereoLineCoeff
{
	double Xcoef;
	double XcoefA;
	double XcoefB;
	double XcoefAB;
	double Ycoef;
	double YcoefA;
	double YcoefB;
	double YcoefAB;
	double Zcoef;
	double ZcoefA;
	double ZcoefB;
	double ZcoefAB;
};

/// <summary>
/// Camera
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct Camera
{
	/// <summary>
	/// size of the camera view, used during calibration
	/// </summary>
	inline_array<float, 2> imgSize2D32s;
	/// <summary>
	/// intinsic camera parameters: [ fx 0 cx; 0 fy cy; 0 0 1 ]
	/// </summary>
	inline_array<float, 9> matrix;
	/// <summary>
	/// distortion coefficients - two coefficients for radial distortion
	/// and another two for tangential: [ k1 k2 p1 p2 ]
	/// </summary>
	inline_array<float, 4> distortion;
	inline_array<float, 9> rotMatr;
	/// <summary>
	/// rotation matrix and transition vector relatively
	/// to some reference point in the space
	/// </summary>
	inline_array<float, 3> transVect;
};

/// <summary>
/// StereoCamera
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct StereoCamera
{
	/// <summary>
	/// two individual camera parameters
	/// </summary>
	inline_array_ex<IntPtr, sizeof(size_t), 3> camera;
	/// <summary>
	/// fundamental matrix
	/// </summary>
	inline_array<float, 9> fundMatr;
	/// <summary>
	/// New part for stereo
	/// </summary>
	inline_array_ex<Point3D32f, sizeof(float)*3, 2> epipole;
	/// <summary>
	/// coordinates of destination quadrangle after
	/// epipolar geometry rectification
	/// </summary>
	inline_array2d_ex<Point3D32f, sizeof(float)*3, 4, 2> quad;
	/// <summary>
	/// coefficients for transformation
	/// </summary>
	inline_array3d<double, 2, 3, 3> coeffs;
	inline_array2d_ex<Point3D32f, sizeof(float)*3, 4, 2> border;
	/// <summary>
	/// warpSize2D32s
	/// </summary>
	Size2D32s warpSize2D32s;
	IntPtr lineCoeffs;
	/// <summary>
	/// flag set to 1 if need to swap cameras for good reconstruction
	/// </summary>
	int needSwapCameras;
	inline_array<float, 9> rotMatrix;
	inline_array<float, 3> transVector;
};

/// <summary>
/// ContourOrientation
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct ContourOrientation
{
	inline_array<float, 2> egvals;
	inline_array<float, 4> egvects;
	float max, min;
	/// <summary>
	/// minimum and maximum projections
	/// </summary>
	int imax, imin;
};


/// <summary>
/// FaceTracker
/// </summary>
[StructLayoutAttribute(LayoutKind::Explicit, Size=0)]
public value struct FaceTracker
{
	// black box
};

/// <summary>
/// FaceData
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct FaceData
{
	Rect MouthRect;
	Rect LeftEyeRect;
	Rect RightEyeRect;
};

/// <summary>
/// 3dTracker2dTrackedObject
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct Tracker2DTrackedObject3D
{
	int id;
	Point2D32f p;
};

/// <summary>
/// 3dTrackerTrackedObject
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct TrackerTrackedObject3D
{
	int id;
	Point3D32f p;
};

/// <summary>
/// 3dTrackerCameraInfo
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct TrackerCameraInfo3D
{
	unsigned char valid;
	/// <summary>
	/// maps camera coordinates to world coordinates
	/// </summary>
	inline_array2d<float, 4, 4> mat;
	/// <summary>
	/// copied from intrinsics so this structur
	/// </summary>
	Point2D32f principal_point;
};

/// <summary>
/// 3dTrackerCameraIntrinsics
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct TrackerCameraIntrinsics3D
{
	Point2D32f principal_point;
	inline_array<float, 2> focal_length;
	inline_array<float, 4> distortion;
};

/// <summary>
/// VoronoiSite2D
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct VoronoiSite2DFields
{
	inline_array_ex<IntPtr, sizeof(size_t), 2> node;
	inline_array_ex<IntPtr, sizeof(size_t), 2> edge;
};

/// <summary>
/// VoronoiSite2D
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct VoronoiSite2D
{
	VoronoiSite2DFields fields;
	inline_array_ex<IntPtr, sizeof(size_t), 2> next;
};

/// <summary>
/// VoronoiEdge2DFields
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct VoronoiEdge2DFields
{
	inline_array_ex<IntPtr, sizeof(size_t), 2> node;
	inline_array_ex<IntPtr, sizeof(size_t), 2> site;
	inline_array_ex<IntPtr, sizeof(size_t), 4> next;
};

/// <summary>
/// VoronoiEdge2D
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct VoronoiEdge2D
{
	VoronoiEdge2DFields fields;
};

/// <summary>
/// VoronoiNode2DFields
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct VoronoiNode2DFields
{
	SetElemFields set_elem_fields;
	Point2D32f pt;
	float radius;
};

/// <summary>
/// VoronoiNode2D
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct VoronoiNode2D
{
	VoronoiNode2DFields fields;
};

/// <summary>
/// VoronoiDiagram2DFields
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct VoronoiDiagram2DFields
{
	GraphFields graph_fields;
	IntPtr sites;
};

/// <summary>
/// VoronoiDiagram2D
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct VoronoiDiagram2D
{
	VoronoiDiagram2DFields fields;
};

/// <summary>
/// LCMEdge
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct LCMEdge
{
	GraphEdgeFields graph_edge_fields;
	IntPtr chain;
	float width;
	int index1;
	int index2;
};

/// <summary>
/// LCMNode
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct LCMNode
{
	GraphVertexFields graph_vertex_fields;
	IntPtr contour;
};

[UnmanagedFunctionPointerAttribute(CallingConvention::Cdecl)]
public delegate void ReleaseBGStatModelFunc(IntPtr bg_model);

[UnmanagedFunctionPointerAttribute(CallingConvention::Cdecl)]
public delegate int UpdateBGStatModelFunc(IntPtr curr_frame, IntPtr bg_model );

/// <summary>
/// BGStatModelFields
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct BGStatModelFields
{
	/// <summary>
	/// type of BG model
	/// </summary>
	int type;
	IntPtr release;
	IntPtr update;
	/// <summary>
	/// 8UC3 reference background image
	/// </summary>
	IntPtr background;
	/// <summary>
	/// 8UC1 foreground image
	/// </summary>
	IntPtr foreground;
	/// <summary>
	/// 8UC3 reference background image, can be null
	/// </summary>
	IntPtr layers;
	/// <summary>
	/// can be zero
	/// </summary>
	int layer_count;
	/// <summary>
	/// storage for foreground_regions
	/// </summary>
	IntPtr storage;
	/// <summary>
	/// foreground object contours
	/// </summary>
	IntPtr foreground_regions;
};

/// <summary>
/// foreground object contours
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct BGStatModel
{
	BGStatModelFields fields;
};

/// <summary>
/// See the above-referenced Li/Huang/Gu/Tian paper
/// for a full description of these background-model
/// tuning parameters.
/// Nomenclature:  'c'  == "color", a three-component red/green/blue vector.
/// We use histograms of these to model the range of
/// colors we've seen at a given background pixel.
/// 'cc' == "color co-occurrence", a six-component vector giving
/// RGB color for both this frame and preceding frame.
/// We use histograms of these to model the range of
/// color CHANGES we've seen at a given background pixel.
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct FGDStatModelParams
{
	/// <summary>
	/// Quantized levels per 'color' component. Power of two, typically 32, 64 or 128.
	/// </summary>
	int Lc;
	/// <summary>
	/// Number of color vectors used to model normal background color variation at a given pixel.
	/// </summary>
	int N1c;
	/// <summary>
	/// Number of color vectors retained at given pixel. Must be > N1c, typically ~ 5/3 of N1c.
	/// </summary>
	int N2c;
	/// <summary>
	/// Quantized levels per 'color co-occurrence' component. Power of two, typically 16, 32 or 64.
	/// Used to allow the first N1c vectors to adapt over time to changing background.
	/// </summary>
	int Lcc;
	/// <summary>
	/// Number of color co-occurrence vectors used to model normal background color variation at a given pixel.
	/// </summary>
	int N1cc;
	/// <summary>
	/// Number of color co-occurrence vectors retained at given pixel. Must be > N1cc, typically ~ 5/3 of N1cc.
	/// </summary>
	int N2cc;
	/// <summary>
	/// If TRUE we ignore holes within foreground blobs. Defaults to TRUE.
	///  Used to allow the first N1cc vectors to adapt over time to changing background.
	/// </summary>
	int is_obj_without_holes;
	/// <summary>
	/// Number of erode-dilate-erode foreground-blob cleanup iterations.
	/// </summary>
	int perform_morphing;
	/// <summary>
	/// How quickly we forget old background pixel values seen. Typically set to 0.1
	/// These erase one-pixel junk blobs and merge almost-touching blobs. Default value is 1.
	/// </summary>
	float alpha1;
	/// <summary>
	/// "Controls speed of feature learning". Depends on T. Typical value circa 0.005.
	/// </summary>
	float alpha2;
	/// <summary>
	/// Alternate to alpha2, used (e.g.) for quicker initial convergence. Typical value 0.1.
	/// </summary>
	float alpha3;
	/// <summary>
	/// Affects color and color co-occurrence quantization, typically set to 2.
	/// </summary>
	float delta;
	/// <summary>
	/// "A percentage value which determines when new features can be recognized as new background." (Typically 0.9).
	/// </summary>
	float T;
	/// <summary>
	/// Discard foreground blobs whose bounding box is smaller than this threshold.
	/// </summary>
	float minArea;
};

/// <summary>
/// BGPixelCStatTable
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct BGPixelCStatTable
{
	float Pv, Pvb;
	inline_array<byte, 3> v;
};

/// <summary>
/// BGPixelCCStatTable
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct BGPixelCCStatTable
{
	float Pv, Pvb;
	inline_array<byte, 6> v;
};

/// <summary>
/// BGPixelStat
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct BGPixelStat
{
	float Pbc;
	float Pbcc;
	IntPtr ctable;
	IntPtr cctable;
	byte is_trained_st_model;
	byte is_trained_dyn_model;
};

/// <summary>
/// FGDStatModel
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct FGDStatModel
{
	BGStatModelFields fields;
	IntPtr pixel_stat;
	IntPtr Ftd;
	IntPtr Fbd;
	IntPtr prev_frame;
	FGDStatModelParams modelParams;
};

/// <summary>
/// GaussBGStatModelParams
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct GaussBGStatModelParams
{
	/// <summary>
	/// = 1/alpha
	/// </summary>
	int win_size;
	int n_gauss;
	double bg_threshold, std_threshold, minArea;
	double weight_init, variance_init;
};

/// <summary>
/// GaussBGValues
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct GaussBGValues
{
	int match_sum;
	double weight;
	inline_array<double, CV_BGFG_MOG_NCOLORS> variance;
	inline_array<double, CV_BGFG_MOG_NCOLORS> mean;
};

/// <summary>
/// GaussBGPoint
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct GaussBGPoint
{
	IntPtr g_values;
};

/// <summary>
/// GaussBGModel
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct GaussBGModel
{
	BGStatModelFields fields;
	GaussBGStatModelParams modelParams;
	IntPtr g_point;
	int countFrames;
};

/// <summary>
/// BGCodeBookElem
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct BGCodeBookElem
{
	IntPtr next;
	int tLastUpdate;
	int stale;
	inline_array<unsigned char, 3> boxMin;
	inline_array<unsigned char, 3> boxMax;
	inline_array<unsigned char, 3> learnMin;
	inline_array<unsigned char, 3> learnMax;
};

/// <summary>
/// BGCodeBookModel
/// </summary>
[StructLayoutAttribute(LayoutKind::Sequential)]
public value struct BGCodeBookModel
{
	Size2D32s size;
	int t;
	inline_array<unsigned char, 3> cbBounds;
	inline_array<unsigned char, 3> modMin;
	inline_array<unsigned char, 3> modMax;
	IntPtr cbmap;
	IntPtr storage;
	IntPtr freeList;
};
//////////////////////////////////////////////////////////////////////////
NAMESPACE_END
//////////////////////////////////////////////////////////////////////////